//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#if _MSC_VER > 1000
#pragma once
#endif

#ifndef __HELPER_H__
#define __HELPER_H__

#define Lock(hCritical)   do {AuraCriticalSection_Enter(hCritical); }while(0)
#define Unlock(hCritical) do {AuraCriticalSection_Leave(hCritical); }while(0)

#define THREAD_START_SLEEP() \
    do { \
        CThread * pThread = NULL; \
        PVoid pLock = NULL; \
        pLock = _Elastos_SequencedContext_Leave(); \
        pThread = static_cast<CThread *>(GetCurrentThread_Expected()); \
        if (NULL != pThread) { \
            pThread->SetThreadState(ThreadState_Sleeping); \
        } \
        do


#define THREAD_END_SLEEP  \
        while(0); \
        if (NULL != pThread) { \
            pThread->SetThreadState(ThreadState_Running); \
        } \
        _Elastos_SequencedContext_Enter(pLock); \
    }while(0)


#define THREAD_START_SLEEP_NAMED() \
    do { \
        CThread * pThread = NULL; \
        pThread = static_cast<CThread *>(GetCurrentThread_Expected()); \
        pThread->SetThreadState(ThreadState_Sleeping); \
        do


#define THREAD_END_SLEEP_NAMED  \
        while(0); \
        pThread->SetThreadState(ThreadState_Running); \
    }while(0)


// helper functions.

EXTERN Boolean IsMainThread(
    /* [in] */ IThread * pThread);

EXTERN Boolean IsCurrentThread(
    /* [in] */ IThread * pThread);

EXTERN Boolean IsCurrentProcessId(
    /* [in] */ ProcessId processId);

EXTERN IThread * GetCurrentThread_Expected();

#endif //__HELPER_H__

